package domainModel;

import java.util.Date;

/**
 * The Class Post.
 */
public class Post implements PostInt {

	/** The counter. help making the id of the post unique (as autoIncrement).*/
	private static int counter = 0; 
	
	/** The id. */
	private int id;
	
	/** The title. */
	private String title;
	
	/** The content. */
	private String content;
	
	/** The creation time. */
	private Date creationTime;
	
	/** The editing time. */
	private Date editingTime;
	
	/** The creator. the member that create the post.*/
	private MemberInt creator;
	
	/**
	 * Instantiates a new post. parameter constructor.
	 *
	 * @param creator the creator
	 * @param title the title
	 * @param content the content
	 */
	public Post(MemberInt creator, String title, String content){
		this.setId();
		this.setCreationTime();
		this.setEditingTime(new Date());
		this.setTitle(title);
		this.setContent(content);
		this.setCreator(creator);
	}
	
	/**
	 * Sets the creator.
	 *
	 * @param creator the new creator
	 */
	public void setCreator(MemberInt creator){
		this.creator = creator;
	}
	
	/* (non-Javadoc)
	 * @see domainModel.PostInt#getContent()
	 */
	@Override
	public String getContent() {
		return this.content;
	}

	/* (non-Javadoc)
	 * @see domainModel.PostInt#getCreationTime()
	 */
	@Override
	public Date getCreationTime() {
		return this.creationTime;
	}

	/* (non-Javadoc)
	 * @see domainModel.PostInt#getEditingTime()
	 */
	@Override
	public Date getEditingTime() {
		return this.editingTime;
	}

	/* (non-Javadoc)
	 * @see domainModel.PostInt#getId()
	 */
	@Override
	public int getId() {
		return this.id;
	}

	/* (non-Javadoc)
	 * @see domainModel.PostInt#getTitle()
	 */
	@Override
	public String getTitle() {
		return this.title;
	}

	/**
	 * Sets the creation time.
	 */
	private void setCreationTime() {
		this.creationTime = new Date();
	}

	/* (non-Javadoc)
	 * @see domainModel.PostInt#setCreationTime(java.util.Date)
	 */
	public void setCreationTime(Date ctime){
		this.creationTime = ctime;
	}
	
	/* (non-Javadoc)
	 * @see domainModel.PostInt#setEditingTime(java.util.Date)
	 */
	@Override
	public void setEditingTime(Date etime) {
		this.editingTime = etime;
	}

	/**
	 * Sets the id.
	 */
	private void setId() {
		this.id = counter;
		counter++;
	}

	/* (non-Javadoc)
	 * @see domainModel.PostInt#setTitle(java.lang.String)
	 */
	@Override
	public void setTitle(String title) {
		this.title = title;
	}

	/* (non-Javadoc)
	 * @see domainModel.PostInt#setContent(java.lang.String)
	 */
	@Override
	public void setContent(String content) {
		this.content = content;
	}

	/* (non-Javadoc)
	 * @see domainModel.PostInt#getCreator()
	 */
	@Override
	public MemberInt getCreator() {
		return this.creator;
	}
	
	/* (non-Javadoc)
	 * @see domainModel.PostInt#editPost(java.lang.String, java.lang.String)
	 */
	@Override
	public void editPost(String newContent,String newTitle) {
		setContent(newContent);
		setTitle(newTitle);
		Date time = new Date();
		setEditingTime(time);
	}
	
	
	public void setId(int id){
		this.id = id;
	}
	
	public PostInt clone() 
	{
		PostInt post = new Post(this.creator,this.title,this.content);
		post.setId(this.id);
		
		return post;
	}
	
}
